import { api } from "@/request";
import {
  httpServer,
  PutUserProps,
  UserProps,
  FindColloectByUserIdProps,
  CollectItemProps,
  BeforeHaveThisBehaviorProps,
} from "@/api/api";

// 登录
export const putUser: httpServer<PutUserProps, UserProps> = ({ id, data }) => {
  return api.put({
    url: `api/user/putUser/${id}`,
    data,
  });
};

// 通过用户di查询我收藏了哪些
export const findColloectByUserId: httpServer<
  FindColloectByUserIdProps,
  CollectItemProps
> = async ({ userId }) => {
  console.log("去请求");
  return api.get({
    url: `api/collect/findUserCollect/${userId}`,
  });
};

// 通过用户di查询我举报了哪些
export const findReportByUserId: httpServer<
  FindColloectByUserIdProps,
  CollectItemProps
> = async ({ userId }) => {
  return api.get({
    url: `api/report/findReportByUserId/${userId}`,
  });
};

// 通过pushlis_id来判断该用户是否已经收藏过，或者举报过，或者助力过
export const beforeHaveThisBehavior: httpServer<
  BeforeHaveThisBehaviorProps
> = ({ publish_id, userId, type }) => {
  let url = "";
  if (type === "collect") {
    url = `api/user/findCollectHasPublishId/${publish_id}/${userId}`;
  }
  if (type === "rocket") {
    url = `api/user/findRocketHasPublishId/${publish_id}/${userId}`;
  }
  if (type === "report") {
    url = `api/user/findReportsHasPublishId/${publish_id}/${userId}`;
  }
  return api.get({
    url,
  });
};
